package com.ymatou.iapi.sellercs.testcase;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.sellercs.parameter.CancelSetMessageSessionImportantBean;
import com.ymatou.iapi.sellercs.parameter.SendMessageBean;
import com.ymatou.iapi.sellercs.parameter.SetMessageSessionImportantBean;
import com.ymatou.iapi.sellercs.service.CancelSetMessageSessionImportantCall;
import com.ymatou.iapi.sellercs.service.SetMessageSessionImportantCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
/**
*取消设置消息会话重要
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CancelSetMessageSessionImportant{
	private static CancelSetMessageSessionImportantBean cancelsetmessagesessionimportantBean;
	private static CancelSetMessageSessionImportantCall cancelsetmessagesessionimportantCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static String sellername = EnvSetup.getData("autotest_sellerName1");
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	private static ImDefaultWapper im;
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("取消设置消息会话重要");
	}

	@Before
	public void caseUp() throws ClientProtocolException, IOException {
		cancelsetmessagesessionimportantBean=new CancelSetMessageSessionImportantBean();
		cancelsetmessagesessionimportantCall=new CancelSetMessageSessionImportantCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
		 im=new ImDefaultWapper();
		 SellerCSIMCallService.OffLine(sellerId, null);
		SellerCSIMCallService.OffLine(zsellerId, null);
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cancelsetmessagesessionimportantCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelSetMessageSessionImportant_001() {
		Logger.start(true,"取消设置消息会话重要成功");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			SellerCSIMCallService.SetMessageSessionImportant(userId, sellerId);
			
			cancelsetmessagesessionimportantBean.setUserId(sellerId);
			cancelsetmessagesessionimportantBean.setToUserId(userId);
			cancelsetmessagesessionimportantCall.setData(cancelsetmessagesessionimportantBean);
			cancelsetmessagesessionimportantCall.callService();			
			Logger.verifyEquals("200", cancelsetmessagesessionimportantCall.getString("Status"), "验证Status");
			List<Map> list =im.selectTotalCount(sellerId, userId);
			Logger.verifyEquals(0, list.get(0).get("IsImportant"), "验证重要信息标志");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}